package org.xilin

class MyxilinController {

    def authenticateService
    def role = ''
    def beforeInterceptor = {
        role = authenticateService.ifAnyGranted('ROLE_USER,ROLE_TEACHER,ROLE_ADMIN')? 'any' : ''
    }

    def index = {
        def user = authenticateService.userDomain()

        if(!session.roles){
            render "You need to sign in first to access My Xilin!"
            return
        }
        if(session.roles.contains('ROLE_ADMIN')) {
            redirect(uri:"/admin")
            return
        }
        if(session.roles.contains('ROLE_USER')) {
            def familyInstance = Family.findByUserId(user.username)
            //[userInstance: user, familyInstance: familyInstance]
//            session.family = familyInstance
            render(template: "menuContent", model: [userInstance: user, familyInstance: familyInstance])
        }
    }
}
